class CostOverviewController < ApplicationController
  def index
    @dinnermoments = Dinnermoment.find(:all)    
    
    @users = User.find(:all)
    #array key = user_id value = kosten
    @costs = Array.new(@users.size > 0 ? @users.size-1 : 0)
    
    @users.each do |user|
      @costs[user.id-1] = 0
      eatersmoment = user.eaters.find_all_by_user_id(user)
      kook = false
      eatersmoment.each do |eatermoment|
        dinnermoment = Dinnermoment.find(eatermoment.dinnermoment_id)
        if (dinnermoment.kook == user.id && !kook)
          @costs[user.id-1] -= dinnermoment.cost
          kook = true
        end
        
        @costs[user.id-1] += dinnermoment.cost/dinnermoment.eaters.size 
      end
    end  
  end
end
